// QRect.cpp: implementation of the CQRect class.
//
//////////////////////////////////////////////////////////////////////
#include "QRect.h"
//////////////////////////////////////////////////////////////////////
EXPORT_C CQRect::CQRect() 
{
	left = 0 ;
	top = 0 ;
	right = 0 ;
	bottom = 0 ;
}

EXPORT_C CQRect::CQRect(QINT l, QINT t, QINT width, QINT height)
{
	left = l; 
	top = t; 
	right = left + width ; 
	bottom = top + height ;
}

EXPORT_C CQRect::CQRect(const QRECT& srcRect)
{
	left = srcRect.left ; 
	top = srcRect.top ; 
	right = srcRect.right ; 
	bottom = srcRect.bottom;
}

EXPORT_C CQRect::CQRect(QRECT& srcRect)
{
	left = srcRect.left ; 
	top = srcRect.top ; 
	right = srcRect.right ; 
	bottom = srcRect.bottom;
}
EXPORT_C CQRect::CQRect(QPOINT point, QSIZE size) 
{
	right  = (left = point.x) + size.cx; 
	bottom = (top = point.y) + size.cy; 
}

EXPORT_C QVOID CQRect::Offset(QINT lt_x, QINT lt_y, QINT rb_x, QINT rb_y)
{
	left += lt_x;
	top  += lt_y;
	right += rb_x;
	bottom += rb_y;
}

EXPORT_C QVOID CQRect::Offset(QPOINT lt, QPOINT rb)
{
	Offset(lt.x, lt.y, rb.x, rb.y);
}

EXPORT_C QVOID CQRect::NormalizeRect() 
{
	QINT nTemp;
	if (left > right)
	{
		nTemp = left;
		left = right;
		right = nTemp;
	}
	if (top > bottom)
	{
		nTemp = top;
		top = bottom;
		bottom = nTemp;
	}
}

EXPORT_C QVOID CQRect::MoveToY(QINT y) 
{ 
	bottom = Height() + y; top = y; 
}

EXPORT_C QVOID CQRect::MoveToX(QINT x) 
{
	right = Width() + x; left = x; 
}

EXPORT_C QVOID CQRect::MoveToXY(QINT x, QINT y) 
{ 
	MoveToX(x); MoveToY(y); 
}

EXPORT_C QVOID CQRect::MoveToXY(QPOINT pt) 
{ 
	MoveToX(pt.x); MoveToY(pt.y); 
}


EXPORT_C QVOID CQRect::operator=(const CQRect &a)
{
	left = a.left ;
	top = a.top ;
	right = a.right ;
	bottom = a.bottom ;
}

EXPORT_C QBOOL CQRect::operator==( const CQRect &b)
{
    return (left == b.left && top == b.top && right == b.right && bottom == b.bottom) ;
}

EXPORT_C QBOOL CQRect::operator!=( const CQRect &b)
{
    return !( *this == b);
}

EXPORT_C QBOOL CQRect::IsPointIn( const CQPoint & point)
{
	QBOOL bXIn = QFALSE ;
	QBOOL bYIn = QFALSE ;
	
	if( left <= point.GetX() && right >= point.GetX() )
		bXIn = QTRUE ;

	if( top <= point.GetY() && bottom >= point.GetY() )
		bYIn = QTRUE ;

	return bXIn&&bYIn ;
}

EXPORT_C QVOID CQRect::Move(QINT nX , QINT nY)
{
	QINT nWidth = Width() ;
	QINT nHeight = Height() ;

	left += nX ;
	top += nY ;
	right = left + nWidth ;
	bottom = top + nHeight ;
}

EXPORT_C QVOID CQRect::Shrink(CQSize sz)
{
	Shrink( sz.Width(), sz.Height());
}

EXPORT_C QVOID CQRect::Shrink(QINT nX , QINT nY) 
{
	left  += nX ;
	right -= nX ;

	top += nY ;
	bottom  -= nY ;

	if( QABS(right-left) < 0 ) right = left ;
	if( QABS(bottom-top) < 0 ) bottom = top ;
}
